$(function () {
    $('body').on('click', '#updatePassword', function () {
            var nowPassword = $('input[name="nowPassword"]').val();
            var newPassword = $('input[name="newPassword"]').val();
            var confirmPwd = $('input[name="confirmPwd"]').val();
            if (nowPassword == null || nowPassword == '') {
                $.alert("请输入原密码");
                return;
            }
            if (newPassword == null || newPassword == '') {
                $.alert("请输入新密码");
                return;
            }
            if (confirmPwd == null || confirmPwd == '') {
                $.alert("请输入确认密码");
                return;
            }
            if (newPassword != confirmPwd) {
                $.alert("两次输入新密码不一致");
                return;
            }
            if(nowPassword !=null && $.trim(nowPassword) !=''){
                var encrypt = new JSEncrypt();
                encrypt.setPublicKey(publicKey);
                nowPassword = encrypt.encrypt(nowPassword);
            }
            if(newPassword !=null && $.trim(newPassword) !=''){
                var encrypt = new JSEncrypt();
                encrypt.setPublicKey(publicKey);
                newPassword = encrypt.encrypt(newPassword);
            }
            if(confirmPwd !=null && $.trim(confirmPwd) !=''){
                var encrypt = new JSEncrypt();
                encrypt.setPublicKey(publicKey);
                confirmPwd = encrypt.encrypt(confirmPwd);
            }
            $.ajax({
                url: baseloaction + '/mobile/uc/userInfo/updatePassword',
                type: 'post',
                dataType: 'json',
                data: {
                    "password": nowPassword,
                    "newPassword": newPassword,
                    "confirmPwd": confirmPwd,
                    'sign':sign
                },
                async: false,
                success: function (result) {
                    if (result.success) {
                        $.alert(result.message, function () {
                            window.location.href = baseloaction + "/mobile/uc/userInfo";
                        });
                    } else {
                        sign = result.keyMap.sign;
                        publicKey = result.keyMap.publicKey;
                        $.toast(result.message);
                    }
                }
            });
        })
});